<template>
  <el-container class='home-container'>
    <el-header>
      <div>
        <img class="logo_img"
             src="../../assets/logo.png" />
        <span>教学管理管理平台</span>
      </div>
      <el-button type='info'>安全退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">

        <!--侧边栏菜单区 unique-opened='true' 只保持一个菜单展开 router开启路由 active-text-color 颜色-->
        <el-menu background-color='#545c64'
                 text-color='#fff'
                 active-text-color='#409eff'
                 unique-opened
                 :collapse='isCollapse'
                 :collapse-transition='false'
                 :router='true'
                 :default-active='activePath'>
          <!-- 1级菜单 -->
          <el-submenu :index='item.id + ""'
                      v-for='item in menuList'
                      :key='item.id'>
            <template slot='title'>
              <span>{{item.title}}</span>
            </template>
            <!-- 2级菜单 -->
            <el-menu-item v-for='it in item.subList'
                          :index='it.path + ""'
                          :key='it.id'
                          @click='saveNavState(it.path)'>
              <template slot='title'>
                <span>{{it.title}}{{it.path}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view>

        </router-view>
      </el-main>
    </el-container>
  </el-container>

</template>
<script>
export default {
  data () {
    return {
      menuList: [
        {
          id: 100,
          title: '首页',
          path: '/commonMain',
          subList: [
            {
              id: 1001,
              title: '我的信息',
              path: '/myInfo'
            }
          ]
        },
        {
          id: 200,
          title: '学生',
          path: '/student',
          subList: [
            {
              id: 2001,
              title: '学生管理',
              path: '/adminStudent'
            }
          ]
        },
        {
          id: 300,
          title: '教师',
          path: '/teacher',
          subList: [
            {
              id: 3001,
              title: '教师管理',
              path: '/adminTeacher'
            }
          ]
        },
        {
          id: 400,
          title: '课程',
          path: '/course',
          subList: [
            {
              id: 4001,
              title: '课程管理',
              path: '/adminCourse'
            }
          ]
        },
        {
          id: 500,
          title: '班级',
          path: '/class',
          subList: [
            {
              id: 4001,
              title: '班级管理',
              path: '/adminClass'
            }
          ]
        },
        {
          id: 600,
          title: '选课',
          path: '/choice',
          subList: [
            {
              id: 4001,
              title: '选课管理',
              path: '/adminChoice'
            }
          ]
        }
      ],
      isCollapse: false,
      // 被激活的连接
      activePath: '',
    }
  },
  methods: {
    // 保存二级菜单的路径
    saveNavState (activePath) {
      window.sessionStorage.setItem('activePath', activePath);// 存放点击的二级菜单
      this.activePath = activePath;// 给点击的菜单添加高亮
    },
  },
  created () {
    this.activePath = window.sessionStorage.getItem('activePath');// 取出session里的访问路径

  },
}
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding-left: 0%;
  align-items: center;
  color: #fff;
  font-size: 20px;
  div {
    //左侧div加布局
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-dropdown-link {
  color: #fff;
}
.logo_img {
  width: 20%;
  height: 100%;
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none; // 对其右边框
  }
}
</style>